package com.cantierinformatici.mygym.dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

import com.cantierinformatici.mygym.R;

public class EditItemDialog extends DialogFragment {
	private Intent mIntent;
	private DeleteDialog mDeleteDialogFragment;
	private OnClickListener mDeleteListener;
	private int mEditItemArray;
	
	
	
	public EditItemDialog(){
		super();
		mEditItemArray = R.array.list_item_edit_default;		
	}
	
	public void setIntent(Intent mIntent){
		this.mIntent = mIntent;
	}
	
	public void setArray(int mEditItemArray){
		this.mEditItemArray = mEditItemArray;
	}
	
	public void setDeleteListener(OnClickListener mDeleteListener){
		this.mDeleteListener = mDeleteListener;
	}
	
	@Override
	public void setArguments(Bundle mBundle){
		super.setArguments(mBundle);
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the Builder class for convenient dialog construction
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setItems(mEditItemArray,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						
						switch (which) {
						case 0:
							// Rinomina
							startActivity(mIntent);
							dismiss();
							break;
						case 1:
							// Elimina;
							mDeleteDialogFragment = new DeleteDialog();
							mDeleteDialogFragment.setDeleteListener(mDeleteListener);
							mDeleteDialogFragment.show(getFragmentManager(), null);							
							break;
						case 2:
							dismiss();
							break;
						}
					}
				});
		// Create the AlertDialog object and return it
		return builder.create();
	}
}
